﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IFRS.Web;
using IFRS.Models;
using IFRS.DataAccess.DAL;
using System.Data;
using IFRS_Global;
using System.Globalization;
using System.Threading;

public partial class IFRS_WIN07_3V : PageBase
{
    #region "---------- Events -----------"
    protected void Page_Load(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
        if (!(Page.IsPostBack || Page.IsCallback))
        {            
            this.ViewMenu();            
            if (Request.QueryString["id"] != null)
            {
                this.BindData(Convert.ToInt32(Request.QueryString["id"].ToString()));
            }
            this.SetControl();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }    
    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN07_1S.aspx");
    }
    #endregion
    #region "---------- Methods -----------"    
    private void BindData(int ID)
    {
        List<GSBBondPrice> gSBBondPrice = new List<GSBBondPrice>();
        DataTable dt = new SPR_GSBBondPrice().SEARCH_BYID(ID);
        if (dt.Rows.Count > 0)
        {
            ConvertHelper.ConvertDataTableToObject(dt, gSBBondPrice);

            txtGSBBondCode.Text = gSBBondPrice[0].GSBBondCode;
            txtAllowedReturnDate.Text = gSBBondPrice[0].AllowedReturnDate.DateToString();
            txtAllowedReturnPrice.Text = gSBBondPrice[0].AllowedReturnPrice.ToString();           
            txtStatus.Text = gSBBondPrice[0].IsConfirmed == false ? "สร้างรายการ" : "ยืนยัน";          
        }
    }   
    private void SetControl()
    {
        SetControlReadOnly(form_control);
    }
    protected void SetControlReadOnly(PlaceHolder plcReadOnly)
    {
        foreach (Control ctrl in plcReadOnly.Controls)
        {
            if (ctrl is Button)
            {
                ((Button)ctrl).Enabled = false;
            }
            if (ctrl is TextBox)
            {
                ((TextBox)ctrl).Attributes["readOnly"] = "true";
                ((TextBox)ctrl).BackColor = System.Drawing.Color.FromArgb(224, 224, 224);
            }
            else if (ctrl is DropDownList)
            {
                ((DropDownList)ctrl).Enabled = false;
                ((DropDownList)ctrl).BackColor = System.Drawing.Color.FromArgb(224, 224, 224);
            }
            else if (ctrl is RadioButton)
            {
                ((RadioButton)ctrl).Attributes["readOnly"] = "true";
                ((RadioButton)ctrl).BackColor = System.Drawing.Color.FromArgb(224, 224, 224);
            }
            else if (ctrl is Image)
            {
                ((Image)ctrl).Attributes["disabled"] = "true";
            }
        }
    }
    private void ViewMenu()
    {
        MenuTitleBar = Resources.ifrsMenu.WIN07_3V;
    }
    #endregion
}